import com.google.common.collect.Maps;
import express.bttree.Node;
import express.bttree.OpNode;
import express.bttree.State;
import express.compiler.ExprUtils;

import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;

public class Main {
    public static class TestOpNode extends OpNode{
        private static Map<String, BiFunction<Object, List<Object>, Object>> methods = Maps.newHashMap();

        static {
            methods.put("getlevel",(input, params)->{
                System.out.println(input + "--" + params);
                return 10;
            });
        }

        @Override
        protected Map<String, BiFunction<Object, List<Object>, Object>> getMethods() {
            return methods;
        }
    }

    public static void main(String[] args) {
        String expr = "(getlevel(\"aa\",'false') >= 1 or getlevel(1,2) > 2 or getlevel(3,4) <= 1) and getlevel(5,6) > 1 and getlevel(7,8) != 1 and getlevel(10,11) >= 1";
        //expr = "getlevel(1,2) >= 10";
        Node node = ExprUtils.convert(expr,TestOpNode.class);
        State state = node.execute("chen");
        System.out.println("执行结果：" + state);

//        String expr2 = "1+2*3+4";
//        System.err.println( expr2 + "=" + ExprUtils.arithmetic(expr2));
    }
}
